<template>
  <div>
    <!-- 输入框 -->
    <van-cell-group>
      <van-field v-model="value" placeholder="请输入商品名称" />
    </van-cell-group>
    <!-- 添加商品按钮 -->
    <van-button type="primary" color="#1989fa" block @click="addGoodItem">添加商品</van-button>
  </div>
</template>
<script>
import qs from "querystring";

export default {
  data() {
    return {
      value: ""
    };
  },
  methods: {
    async addGoodItem() {
      const { data: res } = await this.$http.post(
        "/api/addproduct",
        qs.stringify({ name: this.value })
      );
      if (res.status !== 0) {
        return this.$toast.fail("添加商品失败");
      }
      this.$toast.success("添加商品成功");
      this.value = "";
      this.$router.push("/search");
    }
  }
};
</script>
<style lang="less" scoped>
.van-nav-bar {
  background-color: #1989fa;
}
.van-ellipsis {
  color: #fff;
}
.van-nav-bar__text,
.van-icon-arrow-left:before {
  color: #fff;
}
.van-button {
  margin: 40px auto;
  font-size: 16px;
  width: 90%;
}
</style>
